<?php

require_once 'common/common.php';
require_once 'common/conn.php';
$result = array();
$db = new DBC();
if (isset($_GET['usercode']) && isset($_GET['code'])) {
    $code = $_GET['code'];
    $usercode = $_GET['usercode'];
    $sql = "SELECT * FROM t_hibaby_title_packet_record WHERE usercode = '" . $usercode . "' AND titlecode = '" . $code . "'";
    $data = $db->fetchData($sql);
    if (checkArrayNotEmpty($data)) {
        $result['errorNo'] = "3"; //已经完成
        $result['errorMsg'] = "你已购买该题包"; //已经完成
    } else {
        $type = getParameter("type");
        if ($type == "gold" || $type == "dollar") {
            $sql = "INSERT INTO t_hibaby_title_packet_record(usercode,titlecode,createTime,type) VALUES('" . $usercode . "','" . $code . "',now(),'" . $type . "')";
            if ($db->execute($sql)) {
                $result['errorNo'] = "0"; //首次完成
                $result['errorMsg'] = "";
            } else {
                $result['errorNo'] = "1";
                $result['errorMsg'] = "执行错误";
            }
        } else {
            $sql = "INSERT INTO t_hibaby_title_packet_record(usercode,titlecode,createTime) VALUES('" . $usercode . "','" . $code . "',now())";
            if ($db->execute($sql)) {
                $result['errorNo'] = "0"; //首次完成
                $result['errorMsg'] = "";
            } else {
                $result['errorNo'] = "1";
                $result['errorMsg'] = "执行错误";
            }
        }
    }
} else {
    $result['errorNo'] = "2";
    $result['errorMsg'] = "参数不完整";
}

echo json_encode($result);
?>
